home *** CD-ROM | disk | FTP | other *** search
/ CD Concept 6 / CD Concept 06.iso / mac / UTILITAIRE / Little Smalltalk v3.1.4 / C Source / Sources / CLStApp.cp < prev    next >
Text File  |  1995-01-26  |  6KB  |  217 lines

  1. //=============================================================================
  2. //    Little Smalltalk, version 3
  3. //    Written by Tim Budd, Oregon State University, July 1988
  4. //
  5. //    Symantec Think Class Library interface code 
  6. //        ⌐Julian Barkway, April 1994, all rights reserved.
  7. //
  8. //    CLStApp.cp
  9. //    ----------
  10. //    This class performs basic initialisation and other stuff relating to the
  11. //    Little Smalltalk TCL interface.
  12. //=============================================================================
  13.  
  14. #include <string.h>
  15. #include "CLStApp.h"
  16. #include "CLStSwitchboard.h"
  17. #include "CBartender.h"
  18. #include "Global.h"
  19. #include "Constants.h"
  20. #include "Commands.h"
  21. #include "LStResources.h"
  22.  
  23. extern    OSType        gSignature;
  24. extern    CBartender    *gBartender;
  25.  
  26. #define        kExtraMasters        10
  27. #define        kRainyDayFund        45000
  28. #define        kCriticalBalance    40000
  29. #define        kToolboxBalance        20000
  30.  
  31. CLStApp        *gSmalltalk;
  32.  
  33.  
  34. //=============================================================================
  35. // Application initialization. Invoke IApplication to perform all ToolBox init
  36. // calls, allocate memory and other stuff.
  37. //=============================================================================
  38. void CLStApp::ILStApp(void)
  39. {
  40.     Handle                versH;
  41.  
  42.     CApplication::IApplication (kExtraMasters, kRainyDayFund,
  43.                                 kCriticalBalance, kToolboxBalance);
  44.     gSmalltalk = this;
  45.     ErrorSound (NULL);                            // Disable Alert beep
  46.     
  47.     versH = GetResource ('vers', kVersionRes);    // Get the version number
  48.     BlockMove ((*versH) + 6, versionStr, (Size)(*((*versH) + 6) + 1));
  49. }
  50.  
  51.  
  52. //=============================================================================
  53. // Set up the types of files Li'l Smalltalk knows about as well as the 
  54. // application signature.
  55. //=============================================================================
  56. void CLStApp::SetUpFileParameters (void)
  57. {
  58.     inherited::SetUpFileParameters();
  59.  
  60.     sfNumTypes      = kNumTypes;        /* Number of file types in array (max 4) */
  61.     sfFileTypes [0] = kTextType;        /* Text */
  62.     sfFileTypes [1] = kSysImageType;    /* System Image files */
  63.     
  64.     gSignature = kCreator;
  65. }
  66.  
  67.  
  68. //={OVERRIDE}==================================================================
  69. // Store the command for interface processing
  70. //=============================================================================
  71. void CLStApp::DoCommand (long commandNo)
  72. {
  73.     if (commandNo == cmdAbout) {
  74.         DoAbout (0L);
  75.         return;
  76.     }
  77.     if (commandNo < 0) {
  78.         menuID   = HiShort (-commandNo);
  79.         menuItem = LoShort (-commandNo); 
  80.         if (menuID == MENUapple) {
  81.             inherited::DoCommand (commandNo);
  82.             gSmalltalk->smalltalkCmd = FALSE;
  83.             return;
  84.         }
  85.         gSmalltalk->lastEvent.what = mouseDown; // Restore the action removed
  86.                                                  // by LSTSwitchboard::GetAnEvent ()
  87.         gSmalltalk->smalltalkCmd = TRUE;
  88.         return;
  89.     }
  90.                                 // Must be a TCL command
  91.     if (commandNo == cmdQuit)
  92.         Quit ();
  93.     else {
  94.         menuID = 0;
  95.         inherited::DoCommand (commandNo);
  96.         gSmalltalk->smalltalkCmd = FALSE;
  97.     }
  98. }
  99.  
  100.  
  101. //={OVERRIDE}==================================================================
  102. //     Pass responsibility for quitting over to Smalltalk
  103. //=============================================================================
  104. Boolean    CLStApp::Quit (void)
  105. {
  106.     menuID = 0xffff;
  107.     gSmalltalk->smalltalkCmd = FALSE;
  108.     return true;
  109. }
  110.  
  111.  
  112. //={OVERRIDE}==================================================================
  113. //     Create application's switchboard. (Uses CLStSwtchboard)
  114. //=============================================================================
  115.  
  116. void CLStApp::MakeSwitchboard (void)
  117. {
  118.     itsSwitchboard = new (CLStSwitchboard);
  119.     itsSwitchboard->ISwitchboard ();
  120. }
  121.  
  122.  
  123. //=============================================================================
  124. // Process a message alert
  125. //=============================================================================
  126. void CLStApp::DoMessageAlert (char *msg)
  127. {
  128.     Str255            theString, errorStr;
  129.     short            strID, itemID;
  130.  
  131.     strcpy ((char *)errorStr, msg);
  132.     strcpy ((char *)theString, (char *)errorStr);
  133.     
  134.     CtoPstr      ((char *)theString);
  135.     ParamText    (theString, NULL, NULL, NULL);
  136.     CautionAlert (k_OK_alert, NULL);
  137. }
  138.  
  139.  
  140. //=============================================================================
  141. // Process a Yes, No, Cancel alert
  142. //=============================================================================
  143. short CLStApp::DoYNCAlert (char *msg)
  144. {
  145.     Str255            theString, errorStr;
  146.     short            strID, itemID;
  147.  
  148.     InitCursor ();
  149.     strcpy ((char *)errorStr, msg);
  150.     strcpy ((char *)theString, (char *)errorStr);
  151.     
  152.     CtoPstr      ((char *)theString);
  153.     ParamText    (theString, NULL, NULL, NULL);
  154.     itemID = CautionAlert (k_YNC_alert, NULL);
  155.     switch (itemID) {
  156.         case kSetButtonID:
  157.             return (1);
  158.         case kCancelButtonID:
  159.             return (-1);
  160.         case kNoButtonID:
  161.             return (0);
  162.         default: ;
  163.     }
  164. }
  165.  
  166.  
  167. //=============================================================================
  168. // Put up the About Box
  169. //=============================================================================
  170. void CLStApp::DoAbout (long delay)
  171. {
  172.     EventRecord            theEvent;
  173.     GrafPtr                savePort;
  174.     long                ticksNow;
  175.     WindowPtr            aboutWindow;
  176.     PicHandle            aboutPic;
  177.     short                sposX, sposY;
  178.     
  179.     GetPort (&savePort);
  180.     
  181.     aboutWindow = GetNewWindow (kAboutBoxWIND, NULL, (WindowPtr)-1L);
  182.     if (!aboutWindow)
  183.         return;
  184.         
  185.     aboutPic = GetPicture (kAboutBoxPICT);
  186.     SetPort     (aboutWindow);
  187.     DrawPicture (aboutPic, &aboutWindow->portRect);
  188.     TextFont    (3);        /* Geneva */
  189.     TextSize    (9);
  190.     TextMode    (srcXor);
  191.     sposX = StringWidth (versionStr);
  192.     sposX = ((aboutWindow->portRect.right - aboutWindow->portRect.left) / 2) - (sposX / 2);
  193.     sposY = aboutWindow->portRect.bottom - 20;
  194.     MoveTo      (sposX, sposY);
  195.     DrawString  (versionStr);
  196.  
  197.     if (delay > 0L)
  198.         Delay (delay, &ticksNow);
  199.     else {    
  200.         GetNextEvent (keyDownMask + mDownMask, &theEvent);    /* Soak up any events  */
  201.                                                             /* left hanging around */
  202.         while (!GetNextEvent (keyDownMask + mDownMask, &theEvent))
  203.             SystemTask();
  204.     }
  205.     DisposeWindow (aboutWindow);
  206.     SetPort (savePort);
  207. }
  208.  
  209.  
  210. //={OVERRIDE}==================================================================
  211. // Just copy the SFReply to an instance variable.
  212. //=============================================================================
  213. void CLStApp::OpenDocument (SFReply *macReply)
  214. {
  215.     theFile = *macReply;    // Save the SFReply for use later
  216. }
  217.